﻿using System;

namespace Abp0713Demo
{
    public static class RandomHelper
    {

        private static Random _rnd = new Random();
        //随机整数
        //随机小数
        /// <summary>
        /// 随机整数
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max">最大数,不包含此值</param>
        /// <returns></returns>
        public static int Int(int min, int max)
        {
            if (min >= max) return min;
            return _rnd.Next(min, max);
        }
        /// <summary>
        /// 随机小数
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="digits">随机出来的值的小数位数,如果小于等于0表示整数</param>
        /// <returns></returns>
        public static double Double(double min, double max,int digits = 3)
        {
            if (min >= max) return min;

            var rndValue = _rnd.NextDouble();
            if (digits <= 0) digits = 0; //如果小于等于0表示整数

            return Math.Round(min + rndValue*(max - min),digits);
        }
    }
}